/***************************************************************************
 *   Copyright (C) 2008 by beltegeuse   *
 *   beltegeuse@kubuntu-acer   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

//Includes Qt
#include <QObject>
#include <QMainWindow>
#include <QSplashScreen>
#include <QWidget>
#include <QAction>

//Includes interne
//  * CORE
#include "BdApp.h"
#include "BdRegistry.h"
#include "BdBibliotheque.h"
#include "BdTraceTerminal.h"
#include "BdPluginManager.h"
//  * GUI
#include "BdAjouterLivreManuel.h"

BdApp::BdApp(QSplashScreen *splash, QWidget * parent, Qt::WFlags fl) :
  QMainWindow(parent,fl),
  mSplash(splash)
{
  setupUi(this);
  createActions();
  createMenu();
  createConnect();
  
  
}

BdApp::~BdApp()
{
  //Noop
}

void BdApp::createActions()
{
	mActionQuit = new QAction(tr("Quit"), this);
	mActionAjoutLivreManuel = new QAction(tr("Ajout Manuel"), this);
        mActionAjoutEditeurManuel = new QAction(tr("Ajout Manuel"), this);
        mActionNouvelleBibliotheque = new QAction(tr("Nouvelle bibliotheque"), this);
        mActionPluginManager = new QAction(tr("Plugin manager"), this);
}

void BdApp::createMenu()
{
	//menubar BarMenu
	//Construction du menu en lui même.
	mMenuFichier = menuBar()->addMenu(tr("&Fichier"));
	mMenuEdition = menuBar()->addMenu(tr("&Edition"));
	mMenuHelp = menuBar()->addMenu(tr("&Help"));
	mMenuEdtionLivre = mMenuEdition->addMenu(tr("Livre"));
        mMenuEdtionEdition = mMenuEdition->addMenu(tr("Edition"));
	//Ajout des actions
	mMenuFichier->addAction(mActionQuit);
	mMenuEdtionLivre->addAction(mActionAjoutLivreManuel);
        mMenuFichier->addAction(mActionNouvelleBibliotheque);
        mMenuEdtionEdition->addAction(mActionAjoutEditeurManuel);
        mMenuEdition->addAction(mActionPluginManager);
}

void BdApp::createConnect()
{
	//Menu...
	connect(mActionQuit, SIGNAL(triggered()), this, SLOT(close()));
        connect(mActionNouvelleBibliotheque, SIGNAL(triggered()), this, SLOT(createEmptyBibliotheque()));
        connect(mActionAjoutLivreManuel, SIGNAL(triggered()), this, SLOT(ajouterLivreManuel()));
        connect(mActionPluginManager, SIGNAL(triggered()), this, SLOT(pluginManager()));
}

bool BdApp::addBibliotheque(BdBibliotheque* myBiblio)
{
	
}

void BdApp::createEmptyBibliotheque()
{
  BdTraceTerminal::instance()->information("Creation d'une Bibliotheque vide.");
  BdRegistry::instance()->addBibliotheque(new BdBibliotheque(BdRegistry::instance()->getGoodIdBibliotheque()));
}

void BdApp::ajouterLivreManuel()
{
  BdAjouterLivreManuel* myView = new BdAjouterLivreManuel(this);
  myView->show();
}

void BdApp::pluginManager()
{
  BdTraceTerminal::instance()->information("Plugin manager ...");
  BdPluginManager* myPluginManager = new BdPluginManager(this);
}

